import { createRouter, createWebHashHistory } from 'vue-router'

// 引入页面
import Layout from '../views/layout/Layout.vue'
import Login from '../views/login/Login.vue'

const routes = [
  {
    path: '/login',
    component: Login,
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: () => import('../views/home/Home.vue'),
      }
    ]
  },
  {
    path: '/pm',
    component: Layout,
    redirect: '/pm/product',
    children: [
      {
        path: 'product',
        component: () => import('../views/pm/product/List.vue'),
      },
      {
        path: 'addProduct',
        component: () => import('../views/pm/product/Add.vue'),
      },
      {
        path: 'productCategory',
        component: () => import('../views/pm/productCategory/List.vue')
      },
      {
        path: 'productCateAdd',
        component: () => import('../views/pm/productCategory/Add.vue')
      },
      {
        path: 'productCateUpdate',
        component: () => import('../views/pm/productCategory/Update.vue')
      },
    ]
  },
  {
    path: '/om',
    component: Layout,
    redirect: '/pm/order',
    children: [
      {
        path: 'order',
        component: () => import('../views/om/List.vue'),
      },
      {
        path: 'setting',
        component: () => import('../views/om/Setting.vue'),
      }
    ]
  },
  {
    path: '/um',
    component: Layout,
    redirect: '/um/admin',
    children: [
      {
        path: 'admin',
        component: () => import('../views/um/admin/List.vue'),
      },
      {
        path: 'menu',
        component: () => import('../views/um/menu/List.vue'),
      },
      {
        path: 'role',
        component: () => import('../views/um/role/List.vue')
      }
    ]
  },
  // 所有的未定义的路由，统一跳转
  {
    path: '/:catchAll(.*)', // 固定写法
    component: () => import('../views/NotFound.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
